/**
 * 基础请求地址
 */
const baseUri = "http://127.0.0.1:8080"

/**
 * 统一API接口
 */
const api = {
    sys: {
        user: {
            verify: {
                index: baseUri + '/api/sys/user/verify'
            }
        }
    }
};

/**
 * 基础Ajax
 * @param {Object} url
 * @param {Object} data
 * @param {Object} type
 * @param {Object} response
 */
function baseAjax(url, data, type, response) {
    $.ajax({
        "url": url,
        "data": data,
        "type": type,
        "dataType": "json",
        "success": function (res) {
            response(res);
        },
        "error": function (res) {
            alert("请求错误：" + res.responseJSON.message);
            response(res.responseJSON);
        }
    });
}

/**
 * Ajax封装
 */
const ajax = {
    get: function (url, data, response) {
        baseAjax(url, data, "GET", response);
    },
    post: function (url, data, response) {
        baseAjax(url, data, "POST", response);
    },
    put: function (url, data, response) {
        baseAjax(url, data, "PUT", response);
    },
    delete: function (url, data, response) {
        baseAjax(url, data, "DELETE", response);
    },
}